package com.fymxy.question_bank_management.controller;

import com.fymxy.question_bank_management.pojo.ApiResult;
import com.fymxy.question_bank_management.pojo.Student;
import com.fymxy.question_bank_management.service.ManagerService;
import com.fymxy.question_bank_management.service.StudentService;
import com.fymxy.question_bank_management.service.TeacherService;
import com.fymxy.question_bank_management.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ChanngeInfoContorller {
    @Autowired
    private StudentService studentService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private ManagerService managerService;
    @PostMapping("/student/change")
    public ApiResult studentChange(@RequestBody StudentInfo info ){
        this.studentService.update(Integer.parseInt(info.studentID) ,info.name);
        return ApiResultHandler.buildApiResult(200, "请求成功", null);
    }
    @PostMapping("/manager/change")
    public ApiResult managerChange(@RequestBody StudentInfo info ){
        int res=this.managerService.update(Integer.parseInt(info.studentID) ,info.name);
        if (res>0) return ApiResultHandler.buildApiResult(200, "请求成功", null);
        else return ApiResultHandler.buildApiResult(400, "请求失败", null);
    }

    @PostMapping("/teacher/change")
    public ApiResult teacherChange(@RequestBody TeacherInfo info ){
        System.out.println(info.teacherID+"   "+info.name+info.email);
        int res=this.teacherService.update(Integer.parseInt(info.teacherID) ,info.name,info.email);
        if (res>0) return ApiResultHandler.buildApiResult(200, "请求成功", null);
        else return ApiResultHandler.buildApiResult(400, "请求失败", null);
    }

    public static class StudentInfo {
        String studentID;
        String name;


        public StudentInfo() {
        }

        public StudentInfo(String studentID, String name) {
            this.studentID = studentID;
            this.name = name;

        }

        public String getStudentID() {
            return studentID;
        }

        public void setStudentID(String studentID) {
            this.studentID = studentID;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }


    }

    public static class TeacherInfo{
        String teacherID;
        String name;
        String email;

        public TeacherInfo(String teacherID, String name, String email) {
            this.teacherID = teacherID;
            this.name = name;
            this.email = email;
        }

        public TeacherInfo() {
        }

        public String getTeacherID() {
            return teacherID;
        }

        public void setTeacherID(String teacherID) {
            this.teacherID = teacherID;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }
    }

}
